package java8.lombda;

/**
 * @author 周宇
 * @create 2020-05-19 12:51
 * 计算器
 */
public class CalculatorTest {
    public Integer operator(Integer v1, Integer v2, Calculator<Integer> calculator) {
        return calculator.operation(v1, v2);
    }

    public Integer add(Integer v1, Integer v2) {
        return operator(v1, v2, (x, y) -> x + y);
    }

    public Integer subtr(Integer v1, Integer v2) {
        return operator(v1, v2, (x, y) -> {
            return x - y;
        });
    }

    public static void main(String[] args) {
        CalculatorTest calculatorTest = new CalculatorTest();
        System.out.println(calculatorTest.add(10, 10));//加法 20
        System.out.println(calculatorTest.subtr(20, 5));//减法 15
    }
}